 {layout name="common/layout" /}
<style>
	.tabBar>span {
		position: relative;
	}

	.tabBar>span>a {
		display: inline-block;
		height: 100%;
		width: 100%;
		text-align: center;
		line-height: 40px;
	}
</style>
<link rel="stylesheet" type="text/css" href="__MERCHANT_STATIC__/style/css/order/index.css" />
<div class="Hui-article-box" style="margin-top: 37px;">
	<div class="Hui-article" style="top:0px;margin-top:0px !important">
		<div class="cl" style="margin-bottom: 40px;">
						<div class="article-order">
							<h3 class="order_main_title">订单管理</h3>
							<div id="tab_demo" style="padding-left:0">
								<div class="tabBar clearfix order_main_List">
									<span class="order_main_single"><a href="{:url('index')}?type=1">全部订单</a></span>
									<span class="order_main_single"><a href="{:url('index')}?type=2">待发货</a></span>
									<span class="order_main_single"><a href="{:url('index')}?type=7">待续租</a></span>
									<span class="order_main_single"><a href="{:url('index')}?type=6">待归还</a></span>
									<span class="order_main_single"><a href="{:url('index')}?type=3">待结算</a></span>
									<span class="order_main_single"><a href="{:url('index')}?type=4">待退货</a></span>
									<span class="order_main_single"><a href="{:url('index')}?type=5">成功订单</a></span>
								</div>
										<table class="order_table table table-border table-bg  table-bordered">
											<tr class="text-c text-cs">
												<th style="width: 155px;">订单号</th>
												<th style="width: 150px;">产品</th>
												<th>用户名</th>
												<th>数量</th>
												<th>总租金</th>
												<th>押金</th>
												<th>运费</th>
												<th>合计</th>
												<th>起租时间</th>
												<th>归还时间</th>
												<th>订单状态</th>
											</tr>
											{volist name="$data.order_list" id="order"}
											<tr style="height: 40px;" class="text-c">
												<td >
													<a href="{:url('details')}?id={$order['order_id']}">
														{$order.order_order_sn}
													</a>
													{if $order.relet_origin_id}
													(续租)
														<br />
														<a href="{:url('details')}?id={$order['relet_origin_id']}">
															查看原订单
														</a>
													{/if}
												</td>
												<td >{$order.goods_name}</td>
												<td>{$order.user_phone}</td>
												<td>{$order.goods_amount}</td>
												<!--(活动折扣{}%)-->
												<td style="font-weight: bold;">￥{if condition="$order.order_activity_id gt '0'"}
													{$order.order_activity_rent+$order.relet_rent_pirce|sprintf ="%.2f",###}
													{else/}
													{$order.rent_price+$order.relet_rent_pirce}
													{/if}
													{if condition="$order.is_relet gt '0'"}
													(续租:￥{$order.relet_rent_pirce})
													{/if}
												</td>
												<td>￥{$order.order_deposit}{if condition="$order.order_relief_limit gt '0'"}&nbsp;(芝麻信用减免{$order.order_relief_limit}){else /}&nbsp;{/if}</td>
												<td>￥{$order.order_freight}</td>
												<td>￥{if condition="$order.order_activity_id gt '0'"}
													{$order.order_freight+$order.order_deposit+$order.order_activity_rent+$order.relet_rent_pirce}
													{else/}
													{$order.order_freight+$order.order_deposit+$order.rent_price+$order.relet_rent_pirce}
													{/if}（含运费）</td>
												<td>{$order.order_goods_rent_time}</td>
												<td>{$order.order_goods_return_time}</td>
												<td>
													{switch name="$order.order_shipping_status"}
													{case value="1"}
													{if condition="$order.order_status eq '1'"}待支付
													{else /}
													{if condition="($order.order_refund_goods_status eq '1' and $order.order_status eq '2')"}退款成功
													{elseif condition="$order.order_refund_goods_status neq '0'"}退款
													{else /}
													<span class="index_orderType"><a href="{:url('confirm')}?order_id={$order.order_id}">发货</a></span>
													{/if}
													{/if}{/case}
														{case value="2"}{if condition="$order.order_refund_goods_status eq '2'"}<span class="index_orderType"><a href="{:url('jiesuan')}?order_id={$order.order_id}">结算</a></span>{else /}待归还{/if}{/case}
														{case value="3"}{if condition="$order.order_refund_goods_status eq '2'"}<span class="index_orderType"><a href="{:url('jiesuan')}?order_id={$order.order_id}">结算</a></span>{else /}待归还{/if}{/case}
														{case value="4"}{if condition="$order.order_refund_goods_status eq '2'"}<span class="index_orderType"><a href="{:url('jiesuan')}?order_id={$order.order_id}">结算</a></span>{else /}<span class="index_orderType"><a href="{:url('jiesuan')}?order_id={$order.order_id}&type={$data.type}">结算</a></span>{/if}{/case}
														{case value="5"}结算中{/case}
														{case value="6"}{if condition="($order.order_refund_goods_status eq '2') or ($order.order_refund_goods_status eq '4')"}退货成功{else /}成功订单{/if}{/case}
														{case value="7"}{if condition="($order.order_refund_goods_status eq '2') or ($order.order_refund_goods_status eq '4')"}退货成功{else /}成功订单{/if}{/case}
                                                    {case value="9"}
                                                    {if condition="($order.relet_status eq '2')"}
                                                    已续租
                                                    {elseif condition="($order.relet_status eq '3')"}
                                                    拒绝续租{elseif condition="($order.relet_status eq '1')"}
                                                    <span class="index_orderType" style="cursor:pointer" onclick="setReletState('{$order.order_id}','2')">同意</span>
                                                    <span class="index_orderType" style="cursor:pointer" onclick="setReletState('{$order.order_id}','3')">拒绝</span>
                                                    {elseif condition="($order.relet_status eq '4')"}
                                                    取消续租
                                                    {elseif condition="($order.relet_status eq '5')"}
                                                    续租完结
                                                    {/if}{/case}
                                                    {default /}待支付
													{/switch}
												</td>
											</tr>
											{/volist} 
										</table>
								{$data.page}
							</div>
						</div>
					</div>
				</div>
			</div>

<script type="text/javascript" src="https://cdn.bootcss.com/vue/2.4.4/vue.js"></script>
<script>
	$(function () {
		var type = "{$data.type}";
		var num = 1;
		if (type){
            var num = parseInt(type);
        }
        //alert(num);
      	if(num==3|| num==4 || num==5){
			num+=1;
		  }else if(num==6){
			num=3;
		  }else if(num==7){
			num=2;
		  }else if(num==0){
            num=0;
          }else{
			num-=1;
		  }
        //alert(num);
		$.Huitab("#tab_demo .tabBar span", "#tab_demo .tabCon", "current", "click", num)
	});
	var GG = {
		"kk": function (mm) {
			var ym = mm;
		}
	}
	$("#page").initPage(71, 1, GG.kk);
	$("#page1").initPage(71, 1, GG.kk);
	$("#page2").initPage(71, 1, GG.kk);
	$("#page3").initPage(71, 1, GG.kk);
	$("#page4").initPage(71, 1, GG.kk);

	function getCountDays(yy, s) {
		var curDate = new Date(yy, s);
		curDate.setMonth(s);
		curDate.setDate(0);
		return curDate.getDate();
	}

	function showMSG() {
		layer.msg('商品还未归还，无法结算！');
	}
	$(".index_getRecord").click(function(){
		location.href="{:url('Withdraw/withdrawals')}";
	});
	$("#btn").click(function(){
	  if($("select[name='year']").val()=="")
	  {
		  layer.msg('年份不能为空!');
		  return false;
	  }
		if($("select[name='may']").val()=="")
		{
			layer.msg('月份不能为空!');
			return false;
		}
		location.href="billdetail?year="+$("select[name='year']").val()+"&may="+$("select[name='may']").val();
	});

	/* 获取订单数量 */
	$(document).ready(function(){
		$.ajax({
			url: "../../api/index/getOrderCount",
			type: "GET",
			data: {
			},
			async: true,
			dataType: "json",
			success: function (response) {
				var orderNumber=response.data;
				$(".order_main_single>a").each(function(index,element) {
					/* 当前订单循序变更 */
					/* 1，2，7，6，3，4，5 */
					index+=1;
					if(index==7|| index==5 || index==6){
						index-=2;
					}else if(index==3){
						index=7;
					}else if(index==4){
						index=6;
					}else{
						index=index;
					}
					$(this).text($(this).text()+'('+orderNumber[index]+")");
				});
			},
			error: function (error) {

			}
		});
		
	});

	// 设置续租状态
    function setReletState(order_id, relet_state) {
        //alert(order_id);alert(relet_state);
		if (2 == relet_state) {
			$confirm_txt = '确定同意续租？';
		}else{
            $confirm_txt = '确定拒绝续租？';
		}
        layer.confirm($confirm_txt, {
            btn: ['确定', '取消'] //按钮
        }, function () {
            $.ajax({
                url: "../../api/order/setReletStatus",
                type: "POST",
                data: {
                    'order_id' : order_id,
                    'relet_status' : relet_state
                },
                async: true,
                dataType: "json",
                success: function (data) {
                    if(data.status == 1){
                        layer.msg('操作成功');
                        history.go(0);
                    }else{
                        layer.msg('操作失败');
                    }
                },
                error: function (error) {
                    alert('error');
                }
            });

        }, function () {
            layer.closeAll();
            return false;
        });
    }

</script>